<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/client/backgroundManagement/commons/global.jsp" %>
<script type="text/javascript">
    $(function() {

        $('#roleEditForm').form({
            url : '${path }/roleController/edit',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    parent.$.messager.alert('错误', result.msg, 'error');
                }
            }
            
           
        });
        

        $("#description").val('${role.description}');
        $("#type").val('${role.roleType}');
    });
    
    var roleArea = "<%=  request.getAttribute("roleArea")  %>" ; //字符串如何使用EL
	//alert(roleArea+909)
    
    // 以后需改成读取数据库
    //  select '{id: '''||district_name||''', text: '''||district_name||'''}, ' name from sddcgisplatform.city_distirict_townstreet where city_name in ('广州市') group by district_name 
    var gzDist =[  {id: '197', name: '广州市', district: [ 
                       
						{id: '海珠区', text: '海珠区'}, 
						{id: '南沙区', text: '南沙区'}, 
						{id: '天河区', text: '天河区'}, 
						{id: '番禺区', text: '番禺区'}, 
						{id: '黄埔区', text: '黄埔区'}, 
						{id: '增城区', text: '增城区'}, 
						{id: '从化区', text: '从化区'}, 
						{id: '荔湾区', text: '荔湾区'}, 
						{id: '越秀区', text: '越秀区'}, 
						{id: '花都区', text: '花都区'}, 
						{id: '白云区', text: '白云区'}
                     ]}, 

                     {id: '199', name: '深圳市', district: [ 
						{id: '龙岗区', text: '龙岗区'}, 
						{id: '龙华新区', text: '龙华新区'}, 
						{id: '坪山新区', text: '坪山新区'}, 
						{id: '盐田区', text: '盐田区'}, 
						{id: '宝安区', text: '宝安区'}, 
						{id: '福田区', text: '福田区'}, 
						{id: '内伶仃岛', text: '内伶仃岛'}, 
						{id: '大鹏新区', text: '大鹏新区'}, 
						{id: '南山区', text: '南山区'}, 
						{id: '光明新区', text: '光明新区'}, 
						{id: '罗湖区', text: '罗湖区'}
                     ]}, 
                     {id: '200', name: '珠海市', district: [ 
                      {id: '香洲区', text: '香洲区'}, 
                      {id: '斗门区', text: '斗门区'}, 
                      {id: '金湾区', text: '金湾区'} 
                     ]},   
                     {id: '202', name: '佛山市', district: [ 
                      {id: '禅城区', text: '禅城区'}, 
                      {id: '南海区', text: '南海区'}, 
                      {id: '顺德区', text: '顺德区'}, 
                      {id: '三水区', text: '三水区'}, 
                      {id: '高明区', text: '高明区'} 
                     ]},   
                     {id: '207', name: '惠州市', district: [ 
						{id: '惠阳区', text: '惠阳区'}, 
						{id: '大亚湾区', text: '大亚湾区'}, 
						{id: '惠城区', text: '惠城区'}  
                     ]},   
                     {id: '212', name: '清远市', district: [ 
                      {id: '清城区', text: '清城区'} 
                     ]},
                     {id: 183, name: '长沙市', district: [ 
						{id: '岳麓区', text: '岳麓区'},
						{id: '天心区', text: '天心区'},
						{id: '雨花区', text: '雨花区'},
						{id: '芙蓉区', text: '芙蓉区'}
                     ]},  
                     {id: '213', name: '东莞市', district: [
						{id: '西北区', text: '西北区'}, 
						{id: '西南区', text: '西南区'}, 
						{id: '东北区', text: '东北区'}, 
						{id: '松朗区', text: '松朗区'}, 
						{id: '中心区', text: '中心区'}, 
						{id: '东南区', text: '东南区'}                                     
                     ]}
                 ]; 
                                 
                                 
    var cityData= [{id: '东莞市', text: '东莞市'},{id: '清远市', text: '清远市'},{id: '广州市', text: '广州市'},{id: '深圳市', text: '深圳市'},
                   {id: '珠海市', text: '珠海市'},{id: '佛山市', text: '佛山市'},{id: '惠州市', text: '惠州市'},{id: '中山市', text: '中山市'}
                   ,{id: '长沙市', text: '长沙市'}]
   
	//可查看区域
    $('#roleArea').combotree({
        multiple: true,
        required: true,
    });
                               
    //====赋值===
    //可视区域
        var flag = false; 
        /***/
        if(roleArea=="null"){
        	roleArea=null;
        }else{
        	var areas = roleArea.split(",");
        	for(var x=0;x<areas.length;x++){
        		 
        		var area =areas[x];
        		var isCity = false;
        		debugger;
        		//
        		for(var i=0;i<cityData.length;i++){
        			var city = cityData[i].id;
        			if(area == city){
        				isCity =true;
        			}
        		}
        		
    	 		//多个市时
    	 		if(isCity){
    	 			//
    	 			$('#roleArea').combotree('loadData',cityData);
    	 			//赋值
    	 			$('#roleArea').combotree('setValues',roleArea);
    	 			break;
    	 		}else{
    	 			//市内多区
    		 		for(var g=0;g<gzDist.length;g++){
    		 			if(flag)break;
    		 			var data = gzDist[g];
    		 			if(data.district!=null && data.district.length>0){
    		 				for(var c  =0 ; c<data.district.length;c++){
    		 					 var dist = data.district[c]
    	    		 			if(area == dist.id){
    	    		 				debugger;
    	    		 				$('#roleArea').combotree('loadData',data.district);
    	    	    	 			//赋值
    	    	    	 			$('#roleArea').combotree('setValues',areas);
    	    	    	 			flag=true;
    	    		 				break;  
    	    		 			}
    		 				}
    		 			}

    		 		}
    	 		}
        	}
        	
        }
        
    	$('#city').combobox({
    		//选择城市更新具体行政区
    		onSelect:function(record){
    	 		var cityName = record.value;
    	 		//可跨市时
    	 		if(cityName == '多个城市'){
    	 			
    	 			$("#roleAreaType").val("city")
    	 			$('#roleArea').combotree('loadData',cityData);
    	 		}else{
    	 			$("#roleAreaType").val("distinct")
    	 			//市内多区
    		 		for(var g=0;g<gzDist.length;g++){
    		 			var data = gzDist[g];
    		 			if(cityName == data.name){
    		 				$('#roleArea').combotree('loadData',data.district);
    		 			}
    		 		}
    	 		}

    	 		
    		}
    	})
    
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false" title="" style="overflow: hidden;padding: 3px;">
        <form id="roleEditForm" method="post">
            <table class="grid">
                <tr>
                    <td>角色名称</td>
                    <td><input name="id" type="hidden"  value="${role.roleId}">
                      <input name="roleAreaType" id="roleAreaType"   value="${role.roleAreaType}" type="hidden">
                    <input name="name" type="text" placeholder="请输入角色名称" class="easyui-validatebox" data-options="required:true" value="${role.roleName}"></td>
                </tr>
 <!-- 
                <tr>type="hidden"
                    <td>排序</td>
                    <td><input name="seq"  class="easyui-numberspinner" style="width: 140px; height: 29px;" required="required" data-options="editable:false" value=""></td>
                </tr>
  -->
                <tr>
                    <td>类型</td>
	                <td >
		                <select id="type" name="type" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto'">
                                    <option value="1">用户</option>
                                    <option value="0">管理员</option>
		                </select>
	                </td>
                </tr>
                 <tr>
                <td>可视区域</td>
                	
                   <tr>
                     <td>
	                     <select id="city" class="easyui-combobox" name="city"   style="width: 86px; height: 29px;">
	                         <option value="">请选择</option>
	                         <option>广州市</option>
	                         <option>佛山市</option>
	                         <option>清远市</option>
	                         <option>东莞市</option>
	                         <option>深圳市</option>
	                         <option>长沙市</option>
	                         <option>珠海市</option>
	                         <option>惠州市</option>
	                         <option>中山市</option>
	                         <option>多个城市</option>
	                     </select>
                     </td> 
                     
                     <td><select id="roleArea" name="roleArea" style="width: 350px; height: 29px;"></select></td>
                     </tr>
                
                </tr>
                
                <tr>
                    <td>备注</td>
                    <td colspan="3"><textarea id="description" name="description" rows="" cols="" style="width: 350px;"></textarea></td>
                </tr>
            </table>
        </form>
    </div>
</div>